package com.drojian.provider;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.drojian.review.R;

public class ContentProviderAActivity extends AppCompatActivity {
    private TextView tv1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_content_provider_aactivity);
        tv1 = findViewById(R.id.tv);
    }

    public void queryAll(View view) {
        DB db = new DB(this,"user.db", null, 1);
        SQLiteDatabase database = db.getWritableDatabase();
        Cursor cursor = database.query("book_table", null, null, null, null, null, null);
        StringBuilder builder = new StringBuilder();
        if(cursor.moveToFirst()){
            do{
                int column_age = cursor.getColumnIndex("id");
                int id = cursor.getInt(column_age);
                int column_name = cursor.getColumnIndex("name");
                String name = cursor.getString(column_name);
                builder.append("id:"+id+"   "+"name:"+name+"\n");
            }while (cursor.moveToNext());
        }
        cursor.close();
        tv1.setText(builder);
    }
}